import net from "net";
const html = `<h1>tcp</h1>`;
const responseHeaders = [
  "HTTP/1.0 200 OK",
  "Content-Type: text/html",
  "Content-Length: " + html.length,
  "\r\n",
  html,
];
const http = net.createServer((socket) => {
  socket.on("data", (e) => {
    console.log(e.toString());
    if (/GET/.test(e.toString())) {
      socket.write(responseHeaders.join("\r\n"));
      socket.end();
    }
  });
});
http.listen(8080, () => {
  console.log("server listening on port 8080");
});
